package com.rxh.risk;

import com.rxh.cache.RiskDangerCache;
import com.rxh.cache.SysConstantCache;
import com.rxh.exception.PayException;
import com.rxh.pojo.risk.RiskDanger;
import com.rxh.pojo.sys.SysConstant;
import com.rxh.utils.JsonUtils;
import com.rxh.utils.SystemConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 王德明
 * Date: 2018/9/11
 * Time: 14:53
 * Project: Management_new
 * Package: com.rxh.risk
 */
@Component
public class DangerComponent implements RiskInterface {

    @Autowired
    private SysConstantCache sysConstantCache;

    @Autowired
    private RiskDangerCache riskDangerCache;

    @Override
    public void analysis(RiskContext riskContext) throws PayException {
        Integer webSiteId = riskContext.getMerchantWebSite().getId();
        Integer merId = riskContext.getTradeObject().getMerNo();
        Integer acquirerId = riskContext.getCoreAcquirer().getId();
        String cardNo = riskContext.getTradeObject().getCardNo();
        String email = riskContext.getTradeObject().getBillEmail();
        List<SysConstant> SysConstantList = sysConstantCache.getConstantByGroupNameAndSortValueIsNotNULL(SystemConstant.RISK_LIMIT);
        List<RiskDanger> RiskDangerList = riskDangerCache.getDanger(webSiteId,merId,acquirerId,cardNo,email,SysConstantList);
        if (RiskDangerList.size() > 0) {
            throw new PayException("黑卡库阻止: " + JsonUtils.objectToJson(RiskDangerList),2001);
        }
    }

    @Override
    public String getRiskName() {
        return SystemConstant.RISK_DANGER;
    }

}
